import axios from 'axios'
let fromatDate = function (time) {
  let date = new Date(time);
  let year = date.getFullYear(),
    month = date.getMonth() + 1,
    day = date.getDate(),
    hour = date.getHours(),
    min = date.getMinutes(),
    sec = date.getSeconds();
  let newTime = year + '-' +
    (month < 10 ? '0' + month : month) + '-' +
    (day < 10 ? '0' + day : day) + ' ' +
    (hour < 10 ? '0' + hour : hour) + ':' +
    (min < 10 ? '0' + min : min) + ':' +
    (sec < 10 ? '0' + sec : sec);
  return newTime;
};
let fromatPushTime = function (time) {
  let date = new Date(time);
  let year = date.getFullYear(),
    month = date.getMonth() + 1,
    day = date.getDate();

  let newTime = year + '-' +
    (month < 10 ? '0' + month : month) + '-' +
    (day < 10 ? '0' + day : day);
  return newTime;
};
let post = (Posturl, data) => {
  return new Promise((resolve, reject) => {
    axios({ //调用接口
        method: 'post',
        url: Posturl,
        params: data,
      })
      .then(result => {
        resolve(result)
      })
  })
}
let get = (Geturl, data) => {
  return new Promise((resolve, reject) => {
    axios({ //调用接口
        method: 'get',
        url: Geturl,
        params: data
      })
      .then(result => {
        resolve(result)
      })
  })
}
let formPost = (Posturl, data) => {
  return new Promise((resolve, reject) => {
    axios({ //调用接口
        method: 'post',
        url: Posturl,
        data: data,
        headers: {
          'Content-type': 'application/x-www-form-urlencoded'
        }
      })
      .then(result => {
        resolve(result)
      })
  })
}
let timestampToTime = function (timestamp) {
  var date = new Date(Number(timestamp)); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
  var Y = date.getFullYear();
  var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
  var D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate());
  console.log(Y + M + D)
  return Y + M + D;
};
let fromatPushTime2 = function(time) {
  let date = new Date(time);
  let year = date.getFullYear(),
    month = date.getMonth() + 1,
    day = date.getDate();

  let newTime = year +
    (month < 10 ? '0' + month : month) +
    (day < 10 ? '0' + day : day);
  return newTime;
};
export let Post = post
export let Get = get
export let FromatPushTime = fromatPushTime
export let FromatDate = fromatDate
export let TimestampToTime = timestampToTime
export let FormPost = formPost
export let FromatPushTime2 = fromatPushTime2
